/*
 *  SingletonDefine.h
 *  CmnLib
 *
 *  Created by 21CN Vgo on 11-4-21.
 *  Copyright 2011 __MyCompanyName__. All rights reserved.
 *
 */

#define OBJC_DEF_SINGLETON(className) \
+ (className*) instance;

#define OBJC_IMPL_SINGLETON(className) OBJC_IMPL_SINGLETON_ZONE(className, nil)

#define OBJC_IMPL_SINGLETON_ZONE(className, zoneObj) \
static className *instance   = nil;\
+ (className*) instance\
{\
	@synchronized(self)\
	{\
		if (instance == nil)\
		{\
			[[self allocWithZone:zoneObj] init];\
		}\
	}\
	return instance;\
}\
+ (id)allocWithZone:(NSZone*) zone\
{\
	@synchronized(self)\
	{\
		if (zone != zoneObj && zoneObj == nil)\
		{\
			return [super allocWithZone:zoneObj];\
		}\
		else if (instance == nil)\
		{\
			instance = [super allocWithZone:zone];\
			return instance;\
		}\
	}\
	return nil;\
}\
- (id) copyWithZone:(NSZone *)zone\
{\
	return self;\
}\
- (id) retain\
{\
	return self;\
}\
- (unsigned) retainCount\
{\
	return UINT_MAX;\
}\
- (oneway void) release\
{\
\
}\
- (id) autorelease\
{\
	return self;\
}
